/*
 * JFInterface.java
 *
 * Created on April 8, 2007, 10:30 PM
 */

package assistedpostagger;

import java.io.File;
import java.util.ArrayList;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.SpinnerNumberModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author  Paul Arezina
 */
public class JFInterface extends javax.swing.JFrame {
    
    private MasterController interfaceController;
    
    /** Creates new form JFInterface */
    public JFInterface() {
        try {
            interfaceController = new MasterController();
        } catch (Exception e) {
            System.out.println("Opening config files failed!\n");
        }
        initComponents();
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        jPanel1 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        jLabel9 = new javax.swing.JLabel();
        jLabelCurrentWord = new javax.swing.JLabel();

        jComboBox1 = new javax.swing.JComboBox();
        jLabelReportProgress = new javax.swing.JLabel();
        jButtonPrevWord = new javax.swing.JButton();
        jButtonJumpWord = new javax.swing.JButton();
        jButtonNextWord = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextPaneReport = new javax.swing.JTextPane();
        jLabel1 = new javax.swing.JLabel();
        jSpinnerPriorSent = new javax.swing.JSpinner();
        jLabel2 = new javax.swing.JLabel();
        jSpinnerFutureSent = new javax.swing.JSpinner();
        jLabel3 = new javax.swing.JLabel();
        jSeparator2 = new javax.swing.JSeparator();
        jSeparator1 = new javax.swing.JSeparator();
        jPanelAssist = new javax.swing.JPanel();
        jPanelAssist.setVisible(false);
        jPanel2 = new javax.swing.JPanel();
        jPanel5 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTableBigram = new javax.swing.JTable();
        jPanel6 = new javax.swing.JPanel();
        jLabel6 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTableVocab = new javax.swing.JTable();
        jPanel7 = new javax.swing.JPanel();
        jLabel7 = new javax.swing.JLabel();
        jLabelPrevTag = new javax.swing.JLabel();
        jScrollPane4 = new javax.swing.JScrollPane();
        jTablePrevTag = new javax.swing.JTable();
        jPanel8 = new javax.swing.JPanel();
        jButtonOpenReport = new javax.swing.JButton();
        jButtonSaveReport = new javax.swing.JButton();
        jButtonImportReport = new javax.swing.JButton();
        jPanelUnassist = new javax.swing.JPanel();

        jLabel8 = new javax.swing.JLabel();
        jScrollPane5 = new javax.swing.JScrollPane();
        jTableAllParts = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        getContentPane().setLayout(new java.awt.GridBagLayout());

        jPanel1.setLayout(new java.awt.GridBagLayout());

        jPanel3.setLayout(new java.awt.GridBagLayout());

        jLabel9.setText("Current word:");
        jPanel3.add(jLabel9, new java.awt.GridBagConstraints());
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        jPanel3.add(jLabelCurrentWord, gridBagConstraints);

        jComboBox1.setModel(new POSTagComboBoxModel(interfaceController.getSpeechPartList(), interfaceController.getValidTags()));
        jComboBox1.setEnabled(false);
        jComboBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComboBox1ActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        jPanel3.add(jComboBox1, gridBagConstraints);

        jLabelReportProgress.setFont(new java.awt.Font("Tahoma", 0, 14));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL;
        gridBagConstraints.insets = new java.awt.Insets(3, 3, 3, 3);
        jPanel3.add(jLabelReportProgress, gridBagConstraints);

        jButtonPrevWord.setText("<- Previous");
        jButtonPrevWord.setEnabled(false);
        jButtonPrevWord.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonPrevWordActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 2;
        jPanel3.add(jButtonPrevWord, gridBagConstraints);

        jButtonJumpWord.setText("Jump to Word...");
        jButtonJumpWord.setEnabled(false);
        jButtonJumpWord.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonJumpWordActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 2;
        jPanel3.add(jButtonJumpWord, gridBagConstraints);

        jButtonNextWord.setText("Next ->");
        jButtonNextWord.setEnabled(false);
        jButtonNextWord.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonNextWordActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 2;
        jPanel3.add(jButtonNextWord, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weighty = 1.0;
        jPanel1.add(jPanel3, gridBagConstraints);

        jPanel4.setLayout(new java.awt.GridBagLayout());

        jLabel4.setText("Report text view:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weighty = 1.0;
        jPanel4.add(jLabel4, gridBagConstraints);

        jTextPaneReport.setEditable(false);
        jTextPaneReport.setFont(new java.awt.Font("Tahoma", 0, 18));
        jTextPaneReport.setMaximumSize(new java.awt.Dimension(300, 2147483647));
        jTextPaneReport.setMinimumSize(new java.awt.Dimension(300, 250));
        jTextPaneReport.setPreferredSize(new java.awt.Dimension(300, 250));
        jScrollPane1.setViewportView(jTextPaneReport);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weighty = 5.0;
        jPanel4.add(jScrollPane1, gridBagConstraints);

        jLabel1.setText("Show up to");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 5);
        jPanel4.add(jLabel1, gridBagConstraints);

        jSpinnerPriorSent.setModel(new SpinnerNumberModel(0, 0, 100, 1));
        jSpinnerPriorSent.setEnabled(false);
        jSpinnerPriorSent.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jSpinnerPriorSentStateChanged(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.weighty = 1.0;
        jPanel4.add(jSpinnerPriorSent, gridBagConstraints);

        jLabel2.setText("prior sentences and");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 5);
        jPanel4.add(jLabel2, gridBagConstraints);

        jSpinnerFutureSent.setModel(new SpinnerNumberModel(0, 0, 100, 1));
        jSpinnerFutureSent.setEnabled(false);
        jSpinnerFutureSent.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jSpinnerFutureSentStateChanged(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.weighty = 1.0;
        jPanel4.add(jSpinnerFutureSent, gridBagConstraints);

        jLabel3.setText("future sentences");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 4;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 5);
        jPanel4.add(jLabel3, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weighty = 2.0;
        jPanel1.add(jPanel4, gridBagConstraints);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        jPanel1.add(jSeparator2, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 5.0;
        gridBagConstraints.weighty = 5.0;
        getContentPane().add(jPanel1, gridBagConstraints);

        jSeparator1.setOrientation(javax.swing.SwingConstants.VERTICAL);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        getContentPane().add(jSeparator1, gridBagConstraints);

        jPanelAssist.setLayout(new java.awt.BorderLayout());

        jPanel2.setLayout(new java.awt.GridBagLayout());

        jPanel5.setMinimumSize(new java.awt.Dimension(350, 200));
        jPanel5.setLayout(new java.awt.GridBagLayout());

        jLabel5.setText("Bigram Probabilities:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
        jPanel5.add(jLabel5, gridBagConstraints);

        jScrollPane2.setMinimumSize(new java.awt.Dimension(250, 200));

        jTableBigram.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null},
                {null, null},
                {null, null},
                {null, null}
            },
            new String [] {
                "Tag", "Probability (%)"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTableBigram.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        ListSelectionModel rowBSM = jTableBigram.getSelectionModel();
        rowBSM.addListSelectionListener(new ListSelectionListener() {
            public void valueChanged(ListSelectionEvent e) {
                if (e.getValueIsAdjusting()) return;
                processListSelection(e, jTableBigram);
            }
        });
        jTableBigram.setEnabled(false);
        jScrollPane2.setViewportView(jTableBigram);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weighty = 4.0;
        jPanel5.add(jScrollPane2, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
        gridBagConstraints.insets = new java.awt.Insets(5, 0, 5, 0);
        jPanel2.add(jPanel5, gridBagConstraints);

        jPanel6.setMinimumSize(new java.awt.Dimension(350, 200));
        jPanel6.setLayout(new java.awt.GridBagLayout());

        jLabel6.setText("Word Distribution:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
        jPanel6.add(jLabel6, gridBagConstraints);

        jScrollPane3.setMinimumSize(new java.awt.Dimension(250, 200));

        jTableVocab.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null},
                {null, null},
                {null, null},
                {null, null}
            },
            new String [] {
                "Tag", "Probability (%)"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTableVocab.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        ListSelectionModel rowVSM = jTableVocab.getSelectionModel();
        rowVSM.addListSelectionListener(new ListSelectionListener() {
            public void valueChanged(ListSelectionEvent e) {
                if (e.getValueIsAdjusting()) return;
                processListSelection(e, jTableVocab);
            }
        });
        jTableVocab.setEnabled(false);
        jScrollPane3.setViewportView(jTableVocab);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weighty = 4.0;
        jPanel6.add(jScrollPane3, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        jPanel2.add(jPanel6, gridBagConstraints);

        jPanel7.setMinimumSize(new java.awt.Dimension(350, 200));
        jPanel7.setLayout(new java.awt.GridBagLayout());

        jLabel7.setText("From Previous Tag:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
        jPanel7.add(jLabel7, gridBagConstraints);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weighty = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
        jPanel7.add(jLabelPrevTag, gridBagConstraints);

        jScrollPane4.setMinimumSize(new java.awt.Dimension(250, 200));

        jTablePrevTag.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null},
                {null, null},
                {null, null},
                {null, null}
            },
            new String [] {
                "Tag", "Probability (%)"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTablePrevTag.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        ListSelectionModel rowPSM = jTablePrevTag.getSelectionModel();
        rowPSM.addListSelectionListener(new ListSelectionListener() {
            public void valueChanged(ListSelectionEvent e) {
                if (e.getValueIsAdjusting()) return;
                processListSelection(e, jTablePrevTag);
            }
        });
        jTablePrevTag.setEnabled(false);
        jScrollPane4.setViewportView(jTablePrevTag);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weighty = 4.0;
        jPanel7.add(jScrollPane4, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTH;
        gridBagConstraints.insets = new java.awt.Insets(5, 0, 5, 0);
        jPanel2.add(jPanel7, gridBagConstraints);

        jPanelAssist.add(jPanel2, java.awt.BorderLayout.CENTER);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        getContentPane().add(jPanelAssist, gridBagConstraints);

        jPanel8.setMaximumSize(new java.awt.Dimension(226, 23));
        jPanel8.setLayout(new java.awt.GridBagLayout());

        jButtonOpenReport.setText("Open Report...");
        jButtonOpenReport.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonOpenReportActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        jPanel8.add(jButtonOpenReport, gridBagConstraints);

        jButtonSaveReport.setText("Save Report As...");
        jButtonSaveReport.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonSaveReportActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        jPanel8.add(jButtonSaveReport, gridBagConstraints);

        jButtonImportReport.setText("Import...");
        jButtonImportReport.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonImportReportActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        jPanel8.add(jButtonImportReport, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weighty = 1.0;
        getContentPane().add(jPanel8, gridBagConstraints);

        jPanelUnassist.setPreferredSize(new java.awt.Dimension(300, 750));
        jPanelUnassist.setLayout(new java.awt.GridBagLayout());

        jLabel8.setText("Parts of Speech:");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
        jPanelUnassist.add(jLabel8, gridBagConstraints);

        jScrollPane5.setMinimumSize(new java.awt.Dimension(300, 625));
        jScrollPane5.setPreferredSize(new java.awt.Dimension(300, 750));

        jTableAllParts.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null},
                {null, null},
                {null, null},
                {null, null}
            },
            new String [] {
                "Tag", "Description"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        loadAllTagsTable(jTableAllParts);
        ListSelectionModel rowASM = jTableAllParts.getSelectionModel();
        rowASM.addListSelectionListener(new ListSelectionListener() {
            public void valueChanged(ListSelectionEvent e) {
                if (e.getValueIsAdjusting()) return;
                processListSelection(e, jTableAllParts);
            }
        });
        jScrollPane5.setViewportView(jTableAllParts);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        jPanelUnassist.add(jScrollPane5, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        getContentPane().add(jPanelUnassist, gridBagConstraints);

        pack();
    }// </editor-fold>//GEN-END:initComponents
    
    private void jButtonJumpWordActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonJumpWordActionPerformed
        if (evt.getSource() == jButtonJumpWord) {
            
            String entry = JOptionPane.showInputDialog(this, "Jump to word # :");
            if (entry != null) {
                interfaceController.jumpToWord(Integer.valueOf(entry).intValue());
                updateGUI();
            }
            
        }
    }//GEN-LAST:event_jButtonJumpWordActionPerformed
    
    private void jButtonNextWordActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonNextWordActionPerformed
        if (evt.getSource() == jButtonNextWord) {
            
            interfaceController.nextWord();
            updateGUI();
            
        }
    }//GEN-LAST:event_jButtonNextWordActionPerformed
    
    private void jButtonPrevWordActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonPrevWordActionPerformed
        if (evt.getSource() == jButtonPrevWord) {
            
            interfaceController.previousWord();
            updateGUI();
            
        }
    }//GEN-LAST:event_jButtonPrevWordActionPerformed
    
    private void jSpinnerFutureSentStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jSpinnerFutureSentStateChanged
        if (evt.getSource() == jSpinnerFutureSent) {
            
            Integer i = (Integer) jSpinnerFutureSent.getModel().getValue();
            
            interfaceController.setFutureSentences(i.intValue());
            jTextPaneReport.setText(interfaceController.getSentenceRange());
            
            
        }
    }//GEN-LAST:event_jSpinnerFutureSentStateChanged
    
    private void jSpinnerPriorSentStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jSpinnerPriorSentStateChanged
        if (evt.getSource() == jSpinnerPriorSent) {
            
            Integer i = (Integer) jSpinnerPriorSent.getModel().getValue();
            
            interfaceController.setPriorSentences(i.intValue());
            jTextPaneReport.setText(interfaceController.getSentenceRange());
            
            
        }
    }//GEN-LAST:event_jSpinnerPriorSentStateChanged
    
    private void jButtonSaveReportActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonSaveReportActionPerformed
        
        
        if (evt.getSource() == jButtonSaveReport) {
            
            saveCurrent();
            
        }
        
    }//GEN-LAST:event_jButtonSaveReportActionPerformed
    
    private boolean saveCurrent() {
        
        if (!(interfaceController.isReportAssisted())) {
            if (interfaceController.isAnyReportUnknowns()) {
                
                int return_val = JOptionPane.showConfirmDialog(this, "There are still unknown tags. Continue saving?", "Unknowns Left", JOptionPane.OK_CANCEL_OPTION);
                if (return_val == JOptionPane.CANCEL_OPTION)
                    return false;
                
            }
        }
        
        JFileChooser fc = new JFileChooser(System.getProperty("user.dir"));
        
        int returnVal = fc.showSaveDialog(this);
        
        if (JFileChooser.APPROVE_OPTION == returnVal) {
            File reportFile = fc.getSelectedFile();
            try {
                interfaceController.saveReport(reportFile);
            } catch (Exception e) {
                JOptionPane.showMessageDialog(this, "Error saving " + reportFile.getName(), "Open File Error", JOptionPane.ERROR_MESSAGE);
            }
            
            this.setTitle(reportFile.getName());
        }
        
        return true;
        
    }
    
    
    private void processListSelection(ListSelectionEvent e, JTable t) {
        
        ListSelectionModel lsm = (ListSelectionModel) e.getSource();
        
        if (!(lsm.isSelectionEmpty())) {
            int selectedRow = lsm.getMinSelectionIndex();
            POSTagComboBoxModel PCModel = (POSTagComboBoxModel) jComboBox1.getModel();
            String posSelected = (String) t.getValueAt(selectedRow, 0);
            PCModel.setSelectedAbbrev(posSelected);
        }
        
    }
    
    private void jButtonOpenReportActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOpenReportActionPerformed
        
        JFileChooser fc = new JFileChooser(System.getProperty("user.dir"));
        
        if (evt.getSource() == jButtonOpenReport) {
            
            if (jSpinnerPriorSent.isEnabled()) {
                
                int response = JOptionPane.showConfirmDialog(this, "Do you want to save your work?", "Save?", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
                switch (response) {
                    case JOptionPane.YES_OPTION:
                        if (!(saveCurrent()))
                            return;
                    case JOptionPane.NO_OPTION:
                        break;
                    default:
                        return;
                }
                
            }
            
            
            int returnVal = fc.showOpenDialog(this);
            
            if (JFileChooser.APPROVE_OPTION == returnVal) {
                File reportFile = fc.getSelectedFile();
                try {
                    interfaceController.openReport(reportFile, false);
                } catch (Exception e) {
                    JOptionPane.showMessageDialog(this, "Error opening " + reportFile.getName(), "Open File Error", JOptionPane.ERROR_MESSAGE);
                }
                
                updateGUI();
                this.setTitle(reportFile.getName());
            }
            
            
            
        }
        
        
        
    }//GEN-LAST:event_jButtonOpenReportActionPerformed
    
    private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed
        if (evt.getSource() == jComboBox1) {
            POSTagComboBoxModel PCModel = (POSTagComboBoxModel) jComboBox1.getModel();
            interfaceController.updateCurrentWordTag(PCModel.getSelectedAbbrev());
        }
    }//GEN-LAST:event_jComboBox1ActionPerformed

private void jButtonImportReportActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonImportReportActionPerformed

    JFileChooser fc = new JFileChooser(System.getProperty("user.dir"));
        
        if (evt.getSource() == jButtonImportReport) {
            
            if (jSpinnerPriorSent.isEnabled()) {
                
                int response = JOptionPane.showConfirmDialog(this, "Do you want to save your work?", "Save?", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
                switch (response) {
                    case JOptionPane.YES_OPTION:
                        if (!(saveCurrent()))
                            return;
                    case JOptionPane.NO_OPTION:
                        break;
                    default:
                        return;
                }
                
            }
            
            
            int returnVal = fc.showOpenDialog(this);
            
            if (JFileChooser.APPROVE_OPTION == returnVal) {
                File reportFile = fc.getSelectedFile();
                try {
                    interfaceController.openReport(reportFile, true);
                } catch (Exception e) {
                    JOptionPane.showMessageDialog(this, "Error opening " + reportFile.getName(), "Open File Error", JOptionPane.ERROR_MESSAGE);
                }
                
                updateGUI();
                this.setTitle(reportFile.getName());
            }
            
            
            
        }
    
}//GEN-LAST:event_jButtonImportReportActionPerformed
    
    private void updateGUI() {
        
        jLabelCurrentWord.setText(interfaceController.getCurrentWord());
        jLabelPrevTag.setText(interfaceController.getCurrentPrevTag());
        int wordPosition = interfaceController.getCurrentWordPosition();
        int wordCount = interfaceController.getWordCount();
        
        if (interfaceController.isReportAssisted())
            jPanelAssist.setVisible(true);
        else jPanelAssist.setVisible(false);
        
        jPanelUnassist.setVisible(!(jPanelAssist.isVisible()));
        
        String positionString = "(" + Integer.toString(wordPosition) + " of " + Integer.toString(wordCount) + ")";
        jLabelReportProgress.setText(positionString);
        jButtonJumpWord.setEnabled(true);
        this.jSpinnerPriorSent.setEnabled(true);
        this.jSpinnerFutureSent.setEnabled(true);
        jButtonPrevWord.setEnabled(interfaceController.isPreviousWords());
        jButtonNextWord.setEnabled(interfaceController.isNextWords());
        jComboBox1.setEnabled(true);
        
        POSTagComboBoxModel PCModel = (POSTagComboBoxModel) jComboBox1.getModel();
        PCModel.setSelectedAbbrev(interfaceController.getWordTag());
        
        jTextPaneReport.setText(interfaceController.getSentenceRange());
        
        if (interfaceController.isReportAssisted()) {
            jTablePrevTag.setEnabled(true);
            loadArrayListIntoTable(jTablePrevTag, interfaceController.getPrevTagDist());
            
            if (interfaceController.isCurrentWordVocab()) {
                jTableVocab.setEnabled(true);
                jTableBigram.setEnabled(true);
                loadArrayListIntoTable(jTableVocab, interfaceController.getVocabTagDist());
                loadArrayListIntoTable(jTableBigram, interfaceController.getBigramPosDist());
            } else {
                DefaultTableModel vocabModel = (DefaultTableModel) jTableVocab.getModel();
                DefaultTableModel bigramModel = (DefaultTableModel) jTableBigram.getModel();
                vocabModel.setRowCount(0);
                bigramModel.setRowCount(0);
                jTableVocab.setEnabled(false);
                jTableBigram.setEnabled(false);
            }
        }
        
        ListSelectionModel allTagSelectModel = jTableAllParts.getSelectionModel();
        allTagSelectModel.clearSelection();
        
    }
    
    private void loadArrayListIntoTable(JTable t, ArrayList<POSTuple> a) {
        
        DefaultTableModel dtm = (DefaultTableModel) t.getModel();
        dtm.setRowCount(0);
        Object[] tuple = new Object[2];
        
        for (int i = 0; i < a.size(); i++) {
            tuple[0] = a.get(i).getPos();
            tuple[1] = a.get(i).getPosPrevalence();
            dtm.addRow(tuple);
        }
        
    }
    
    private void loadAllTagsTable(JTable t) {
        
        DefaultTableModel dtm = (DefaultTableModel) t.getModel();
        dtm.setRowCount(0);
        Object[] tuple = new Object[2];
        
        ArrayList speechPartList = new ArrayList(interfaceController.getSpeechPartList());
        
        for (int i = 0; i < speechPartList.size(); i++) {
            String temPair = (String) speechPartList.get(i);
            String[] tempSplit = temPair.split(" - ");
            tuple[0] = tempSplit[0];
            tuple[1] = tempSplit[1];
            dtm.addRow(tuple);
        }
        
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new JFInterface().setVisible(true);
            }
        });
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonImportReport;
    private javax.swing.JButton jButtonJumpWord;
    private javax.swing.JButton jButtonNextWord;
    private javax.swing.JButton jButtonOpenReport;
    private javax.swing.JButton jButtonPrevWord;
    private javax.swing.JButton jButtonSaveReport;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JLabel jLabelCurrentWord;
    private javax.swing.JLabel jLabelPrevTag;
    private javax.swing.JLabel jLabelReportProgress;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPanel jPanelAssist;
    private javax.swing.JPanel jPanelUnassist;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSpinner jSpinnerFutureSent;
    private javax.swing.JSpinner jSpinnerPriorSent;
    private javax.swing.JTable jTableAllParts;
    private javax.swing.JTable jTableBigram;
    private javax.swing.JTable jTablePrevTag;
    private javax.swing.JTable jTableVocab;
    private javax.swing.JTextPane jTextPaneReport;
    // End of variables declaration//GEN-END:variables
    
}
